<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>cookie</title>
</head>
<body>
    <script>

    // document.cookie='good=牛人;'
    // document.write(document.cookie);
        
        /*function setCookie(Name,Value,eDay){
            var date=new Date();
            date.setTime(date.getTime()+eDay*24*3600*1000);
            document.cookie=Name+'='+Value+';expires='+date;
        }
        
        setCookie('name','good',4);*/
        

        //此种方法可不用转化非整天时间,但输入时间格式稍显繁琐;
        function setCookie(Name,Value,eTime){
            var date=new Date(eTime);
            document.cookie=Name+'='+Value+';expires='+date;
        }
        setCookie('name','Jack','2016/12/9 12:00:00');


        // document.write(document.cookie);
        function getCookie(Name){
            var arr=document.cookie.split(';');
            for(var i=0;i<arr.length;i++)
            {
                if(arr[i].trim().indexOf(Name+'=')==0)
                {
                   return arr[i].trim().slice((Name+'=').length);
                }
            }
            return '';
        }

        document.write(getCookie('name'));
        /*var arr=document.cookie.split(';');
        console.log(arr);
        for(var i=0;i<arr.length;i++)
        {
            if(arr[i].trim().indexOf('name=')==0)
            {
                document.write(arr[i].trim().slice('name='.length));
            }
        }*/


    </script>
</body>
</html>